var status = true;
function initPage() {
    $.ajax({
        url: "/sysInfo/info",
        type:"POST",
        dataType:"json",
        success: function (data){
            $("#hxs").text(data.cpu.cpuNum);
            $("#yh_syl").text(data.cpu.used);
            $("#xt_syl").text(data.cpu.sys);
            $("#dq_kxl").text(data.cpu.free);

            $("#mem_znc").text(data.mem.total);
            $("#jvm_znc").text(data.jvm.total);
            $("#mem_yy_nc").text(data.mem.used);
            $("#jvm_yy_nc").text("未知");
            $("#mem_sy_nc").text(data.mem.free);
            $("#jvm_sy_nc").text(data.jvm.free);

            $("#server_name").text(data.sys.computerName);
            $("#server_os").text(data.sys.osName);
            $("#server_ip").text(data.sys.computerIp);
            $("#server_architecture").text(data.sys.osArch);

            $("#jvm_name").text(data.jvm.name);
            $("#jvm_version").text(data.jvm.version);
            $("#jvm_start_time").text(data.jvm.startTime);
            $("#jvm_run_time").text(data.jvm.runTime);
            $("#jvm_home").text(data.jvm.home);
            $("#user_dir").text(data.sys.userDir);

            var html = "";
            var sysFiles = data.sysFiles;
            for (var k = 0; k < sysFiles.length; k++) {
                html += "<tr>";
                html += "<td>" + sysFiles[k].dirName + "</td>";
                html += "<td>" + sysFiles[k].sysTypeName + "</td>";
                html += "<td>" + sysFiles[k].typeName + "</td>";
                html += "<td>" + sysFiles[k].total + "</td>";
                html += "<td>" + sysFiles[k].free + "</td>";
                html += "<td>" + sysFiles[k].used + "</td>";
                var usage = sysFiles[k].usage;
                if (usage > 80){
                    html += "<td class='text-danger'>" + usage + "%</td>";
                } else {
                    html += "<td>" + usage + "%</td>";
                }
            }
            $("#sysFiles").html(html);
            if (status){
                status = false;
                window.setInterval("initPage()",10000);
            }
        },
        error: function() {
            status = false;
        },
    })
}

document.addEventListener("visibilitychange", () => {
    if (document.hidden) {
        // 清除定时任务
        window.clearInterval(initPage);
        console.log("关闭定时器");
    } else {
        // 开启定时任务
    }
});

$(function () {
    // 初始化页面数据
    initPage();
});